import pygame
class Buy :
    
    def __init__(self, price, increase, exp, image, text, surface):
        self.price = price
        self.increase = increase
        self.exp = exp
        self.ending = None
        self.img = image
        self.text = text
        self.screen = surface
        self.font = pygame.font.Font("v-pet./static./font./Alibaba-PuHuiTi-Regular.otf", size = 30)
        self.loop = 0
        
    def pay_return(self, swap, increase, now_exp):
        if swap >= self.price :
            self.ending = True
            self.loop = 200
            if increase + self.increase <= 100 :
                return [swap - self.price, increase + self.increase, now_exp + self.exp, True]
            elif increase + self.increase > 100 :
                return [swap - self.price, 100, now_exp + self.exp, True]
        else :
            self.ending = False
            self.loop = 100
            return [swap, increase, now_exp, False]
    
    def ending_draw (self, position, font = None) :
        if self.ending == False and self.loop > 0 :
            x, y = position
            self.screen.blit(pygame.transform.scale(self.img, (210, 210)), (x, y))
            self.loop -= 1
        elif self.ending == True and self.loop > 0 :
            font = self.font
            color = (0, 0, 0)
            text_surface = font.render(self.text, True, color)
            x, y = position
            self.screen.blit(text_surface, (x, y))
            self.loop -= 1
